<template>
  <div class="hello" id="hell">
    <h1>{{ msg }}</h1>
    <h2>Essential Links</h2>
    <p>{{dataUrl}}</p>
    <button>跳</button>
    <a type="button" id="down_button"><button @click="creat">点击复制图片</button></a>
    <div class="myImg" style="position:relative;">
        <img src="../assets/logo.png">
    </div>
    <a id="btn_download">下载</a>
    <router-link to="/asyncComp">111111111111111111111111111111111111111</router-link>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  data () {
    return {
      msg: 'Welcome to Your Vue.js App',
      dataUrl:''
    }
  },
  methods:{
    creat(){
      let that = this

      this.myHtml2canvas(document.querySelector(".myImg")).then(canvas => {
          document.body.appendChild(canvas);
          this.dataUrl =canvas.toDataURL("image/png");


          document.querySelector('#btn_download').setAttribute('href',this.dataUrl)
          document.querySelector('#btn_download').setAttribute('download','myImg')
      });
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
